package org.bluewhale.export;

import org.bluewhale.hibernate.dao.*;

import java.io.FileWriter;
import java.io.BufferedWriter;
import java.util.List;

/**
 * @param args
 */

public class DbDataExporter {
	
	public static void main(String[] args) throws Exception {
		if (args.length != 1) {
			System.err.println("Usage: DbDataExporter <outputFile>");
			return;
		}
		
		BufferedWriter bw = new BufferedWriter(new FileWriter(args[0]));
		
		/** readed, reading, want book */
		SkUserBookDAO readedBookDao = new SkUserBookDAO();
		List readedBooks = readedBookDao.findAll();
		for (int i = 0; i < readedBooks.size(); i ++) {
			SkUserBook book = (SkUserBook) readedBooks.get(i);
			Integer userId = book.getSkUser().getId();
			Integer bookId = book.getBookId();
			Integer rank = book.getRank();
			bw.write("" + userId + "," + bookId + "," + rank);
			bw.newLine();
		}
		
		bw.close();
		
		
	}

}
